$(document).ready(function(){
    var params = {};
    mzpost({
        url:pub_goods_list,
        data:params,
        success:function(res){
            if(res.code == '2000'){
               var data = res.data;
               
               createList(data);
               
            }else{
                mui.toast(res.msg);
            }
        },
        error:function(err){
            
            mui.toast('获取商品库存错误');
        }
    })
})

function createList(data){
    $.each(data,function(i,item){
        $('#list').append('<li class="mui-table-view-cell mui-media">'+
        '<a>'+
        '<img class="mui-media-object mui-pull-left" src="'+item.img+'">'+
        '<div class="mui-media-body">'+
        '<p class="mui-ellipsis">'+item.name+'</p>'+
        '<h5>￥'+item.orde_money+'</h5>'+
        '<div><label>我要拿货：</label><input id="'+item.id+'input" type="number">件</div>'+
        '<div><button onclick="gotodetail(this)" class="mui-btn mz-xs-btn" id="'+item.id+'">下单预定</button></div>'+
        '</div>'+
        '</a>'+
        '</li>');
    })
}
function gotodetail(obj){
    var id = $(obj).attr('id');
    var inputval = $('#'+id+'input').val();
    if(inputval == ""){
        mui.toast('请输入件数');
        return;
    }
    location.href = './detail/index.html?id='+id+'&num='+inputval;

}